import request from '@/utils/request'
import BaseUrl from '@/utils/BaseUrl'

export function listSysResource(query) {
  return request({
    url: BaseUrl.API_SYS + '/sys/resource/list',
    method: 'post',
    data: query
  })
}

/**
 * 删除角色
 * @param data
 * @returns {AxiosPromise}
 */
export function deleteSysResource(data) {
  return request({
    url: BaseUrl.API_SYS + '/sys/resource/delete',
    method: 'post',
    data: data
  })
}

/**
 * 增加角色
 * @param data
 * @returns {AxiosPromise}
 */
export function addSysResource(data) {
  return request({
    url: BaseUrl.API_SYS + '/sys/resource/add',
    method: 'post',
    data: data
  })
}

/**
 * 修改角色
 * @param data
 * @returns {AxiosPromise}
 */
export function updateSysResource(data) {
  return request({
    url: BaseUrl.API_SYS + '/sys/resource/update',
    method: 'post',
    data: data
  })
}

/**
 * 获取单个角色
 * @param query
 * @returns {AxiosPromise}
 */
export function getSysResource(query) {
  return request({
    url: BaseUrl.API_SYS + '/sys/resource/get',
    method: 'post',
    data: query
  })
}

/**
 * 获取资源树
 */
export function getSysResourceTree(query) {
  return request({
    url: BaseUrl.API_SYS + '/sys/resource/getSysResourceTree',
    async: false,
    data: query
  })
}

/**
 * 校验资源代码是否存在
 * @param data
 */
export function checkResourceCode(query) {
  return request({
    url: BaseUrl.API_SYS + `/sys/resource/checkResourceCode`,
    method: 'post',
    data: query
  })
}
